import pika,sys
from pika import spec

credentials = pika.PlainCredentials("admin", "admin")
conn_params = pika.ConnectionParameters("192.168.1.24", credentials = credentials)

conn_broker = pika.BlockingConnection(conn_params)
channel = conn_broker.channel()

channel.exchange_declare(exchange = "hello-exchange", type = "direct", passive = False, durable = False, auto_delete = False)

def confirm_handler(frame):
	if type(frame.method) == spec.Confirm.SelectOk:
		print "Channel in 'confirm' mode"
	elif type(frame.method) == spec.Basic.Nack:
		if frame.method.delivery_tag in msg_ids:
			print "Message lost!"
	elif type(frame.method) == spec.Basic.Ack:
		if frame.method.delivery_tag in msg_ids:
			print "Confirm received!"
			msg_ids.remove(frame.method.delivery_tag)
	return

channel.confirm_delivery()

msg = sys.argv[1]
msg_props = pika.BasicProperties()
msg_props.content_type = "text/plain"
msg_ids = []

channel.basic_publish(body = msg, exchange = "hello-exchange", properties = msg_props, routing_key = "hi")
msg_ids.append(len(msg_ids) + 1)
channel.close()